#!/bin/bash
# general file-compare verifier

COMPARE() {
	for O in $OFILES; do
		if [ -z "$1" ]; then
			echo "FATAL ERROR IN verif: not enough files in KFILES" >&2
			exit 1
		fi
		if [ ! -r "$O" ]; then
			echo "FATAL ERROR IN verif: missing $O" >&2
			exit 1
		fi
		shift
		cat "$O"
		exit 0
	done
	if [ ! -z "$1" ]; then
		echo "FATAL ERROR IN verif: more files in KFILES: $*" >&2
		exit 1
	fi
}

if [ -z "$OFILES" ]; then
	echo "FATAL ERROR IN verif: missing OFILES variable!" >&2
	exit 1
fi

COMPARE $KFILES
